package com.gientech.gateway;

import javax.annotation.Resource;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
public class GatewayDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayDemoApplication.class, args);
    }

    @Resource
    private RedisTemplate<String, String> redisTemplate;
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    /**
     * 防止存的key值乱码 进行序列化
     * @return
     */
    @Bean
    public RedisTemplate<String, String> redisTemplateInit() {
        this.redisTemplate.setKeySerializer(new StringRedisSerializer());
        this.redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        return this.redisTemplate;
    }

}
